<template>
  <div class="myArticle">
    <van-nav-bar title="我的文章"
    left-arrow
    @click-left="$router.go(-1)"/>
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell class="article-item">
        <template #title>
          <div class="head" v-for="item in list" :key="item.id">
            <div class="con">
              <p class="title van-ellipsis">{{ item.title }}</p>
              <div class="body van-multi-ellipsis--l2">{{ item.content }}</div>
              <div class="foot">收藏 ({{ item.lovenum }}) | 点赞 ({{ item.click }})</div>
            </div>
            <div class="prc">
              <img :src="`http://124.223.14.236:8060/${item.pic}`" alt="" />
            </div>
          </div>
        </template>
      </van-cell>
    </van-list>
  </div>
</template>

<script>
import { myArticleApi } from '@/api/user'
export default {
  data () {
    return {
      loading: false,
      finished: false,
      limit: 10,
      page: 1,
      list: []
    }
  },
  // created () {
  //   this.onLoad()
  // },
  methods: {
    async onLoad () {
      const { data } = await myArticleApi({
        page: this.page,
        limit: this.limit
      })
      // console.log(data)
      this.list.push(...data.data.data)
      this.loading = false
      this.page++
      if (this.limit > data.data.count) {
        this.finished = true
      }
    }
  }
}
</script>

<style lang="less" scoped>
.van-nav-bar {
  background-color: #1989fa;
  // 导航文字
  /deep/ .van-nav-bar__title {
    color: white;
    font-weight: 500;
    font-size: 0.42667rem;
  }
  //修改箭头颜色
  /deep/ .van-icon-arrow-left {
    color: var(--nav-bar-icon-color, #fff) !important;
  }
}
.article-item {
  .head {
    display: flex;
    .con {
      flex: 1;
      overflow: hidden;
      padding-left: 10px;
      p {
        margin: 0;
        line-height: 1.5;
        &.title {
          width: 280px;
        }
        &.other {
          font-size: 10px;
          color: #999;
        }
      }
    }
  }
  .body {
    font-size: 14px;
    color: #666;
    line-height: 1.6;
    margin-top: 10px;
  }
  .foot {
    font-size: 12px;
    color: #999;
    margin-top: 10px;
  }
  .prc {
    flex: 1;
    overflow: hidden;
    padding-left: 30px;
    img {
      width: 100px;
      height: 100px;
    }
  }
}
</style>
